<?php

/*

    MMetaverse - Open Metaverse Access Library

    Copyright (c) 2009 Mary Jane Soft - Marlon J. Manrique

    http://www.maryjanesoft.com
    http://www.marlonj.com

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General
    Public License along with this library; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place, Suite 330,
    Boston, MA  02111-1307  USA

    $Id$

*/

/**
 * @package mjs.mmetaverse.llsd
 */

require_once 'MLLSDParser.class.php';
require_once 'MLLSDEncoder.class.php';

/**
 * Allow encode and decode llsd message, also create known ones.
 */
class MLLSD 
{
    /**
     * Encode the array like a llsd document
     *
     * @param array $data
     * @return string
     */
    public static function encode(array $data) {
        return MLLSDEncoder::encode($data);
    }

    /**
     * Convert to array the llsd document
     *
     * @param string $xml
     * @return array
     */
    public static function decode($xml) {
        return MLLSDParser::parseXML($xml);
    }

    /**
     * Create the LLSD login request 
     *
     * @param string $firstname User First Name
     * @param string $lastname  User Last Name
     * @param string $password  Plain password 
     * @return array
     */
    public static function createLoginRequest($firstname, $lastname, $password) {
        return array
        (
            'first' => $firstname,
            'last' => $lastname,
            'passwd' => '$1$' . md5($password),
            'start' => 'last',
            'channel' => 1,
            'version' => 50,
            'mac' => '00:00:00:00:00:00',
            'agree_to_tos' => '',
            'read_critical' => '',
            'viewer_digest' => '',
            'id0' => '',
            'options' => array(
                'inventory-root',
                'inventory-skeleton',
            ),
        );
    }
}

?>